home *** CD-ROM | disk | FTP | other *** search
- /* ==============
- * NGLIterator.hh
- * ==============
- *
- * Copyright 2000 Joshua Juran
- */
-
- #pragma once
-
- #include "NGLList.hh"
-
- template <class Type>
- class NGLIterator {
- public:
- NGLIterator(NGLList<Type> &inList);
- virtual ~NGLIterator();
-
- virtual bool GetNext(Type &outDatum);
-
- protected:
- NGLList<Type> &mList;
- NGLListNode<Type> *mCurrentNode;
- };
-
- template <class Type>
- NGLIterator<Type>::NGLIterator(NGLList<Type> &inList)
- : mList(inList)
- {
- mCurrentNode = mList.BeginIteration();
- }
-
- template <class Type>
- NGLIterator<Type>::~NGLIterator()
- {
- mList.EndIteration();
- }
-
- template <class Type>
- bool
- NGLIterator<Type>::GetNext(Type &outDatum)
- {
- while (mCurrentNode && mCurrentNode->WasDeleted()) {
- mCurrentNode = mCurrentNode->Next();
- }
- if (mCurrentNode) {
- outDatum = mCurrentNode->Datum();
- mCurrentNode = mCurrentNode->Next();
- return true;
- }
- return false;
- }
-
-